﻿using System;
using System.Text;
using System.Collections;
using System.Xml;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Resources;
using System.Reflection;
using System.Globalization;
using System.Threading;

using Telerik.WebControls;
using UFSoft.UBF.UI.WebControls;
using UFSoft.UBF.UI.Controls;
using UFSoft.UBF.Util.Log;
using UFSoft.UBF.Util.Globalization;

using UFSoft.UBF.UI.IView;
using UFSoft.UBF.UI.Engine;
using UFSoft.UBF.UI.MD.Runtime;
using UFSoft.UBF.UI.ActionProcess;
using UFSoft.UBF.UI.WebControls.ClientCallBack;
using UFIDA.U9.CUST.AITBarCodeBP.Proxy;
using System.Collections.Generic;
using UFIDA.U9.CUST.AITBarCodeBP;
using UFSoft.UBF.ExportService;
using UFIDA.U9.CUST.AITBarCodeUI.utils;
using UFIDA.U9.UI.PDHelper;



/***********************************************************************************************
 * Form ID: 
 * UIFactory Auto Generator 
 ***********************************************************************************************/
namespace UFIDA.U9.CUST.AITBarCodeUI
{
    public partial class AITBarCodeFormWebPart
    {
        #region Custome eventBind
        private void BtnCreateBarCode_Click_Extend(object sender, EventArgs e)
        {
			if (this.Model.AITBarCode.GetSelectedRecordIDs().Length == 0)
				throw new Exception("请选择记录");
			//先保存记录
			this.BtnSave_Click(sender, e);
            //更新条码
            List<long> ids=new List<long>();
			foreach(var rec in this.Model.AITBarCode.GetSelectRecords())
			{
				ids.Add((long)rec["ID"]);
			}
            UpdateBarCodeProxy proxy = new UpdateBarCodeProxy();
			proxy.IDS = ids;
			proxy.Do();
			//刷新界面
			UIUtils.RefreshGridUI(this, null);

            this.BtnCreateBarCode_Click_DefaultImpl(sender, e);
        }

        private void BtnRefresh_Click_Extend(object sender, EventArgs e)
        {
			UIUtils.RefreshGridUI(this, null);
            this.BtnRefresh_Click_DefaultImpl(sender, e);
        }

        private void BtnReload_Click_Extend(object sender, EventArgs e)
        {
			this.Model.ClearErrorMessage();
            CreateBarCode("MOIDS");//依据 生产订单 创建条码记录
            CreateBarCode("QCIDS");//依据 质检单 创建条码记录
            CreateBarCode("ShipIDS");//依据 出货单 创建条码记录
            CreateBarCode("RCVIDS");//依据 收货单 创建条码记录
            this.BtnReload_Click_DefaultImpl(sender, e);
        }

		/// <summary>
		/// 依据弹出列表返回数据,生成条码实体
		/// </summary>
		/// <param name="type">弹出实体类型</param>
        private void CreateBarCode(string type)
        {
            if (this.CurrentState[type] != null)
            {
                //依据弹出返回,调用BP,创建条码实体
                List<long> ids = (List<long>)this.CurrentState[type];
                CreateBarCodeProxy proxy = new CreateBarCodeProxy();
                proxy.EntityType = type;
                proxy.IDS = ids;
                //返回创建的条码ID集合
                List<long> retids = proxy.Do();
                //保存数据,刷新界面
                this.Action.CommonAction.Save(this.Model);
                retids.AddRange(UIUtils.getCurrentIDS(this.Model));
                UIUtils.RefreshGridUI(this,retids);
                //清空缓存
                this.CurrentState[type] = null;
            }
        }
		

        private void QCList_Click_Extend(object sender, EventArgs e)
        {
			//弹出质检单列表
			UIUtils.ShowListDialog(this, this.BtnReload, "cfd49834-05cc-4d45-9e80-a7bfc264ea6d", "质检单");
            //this.ShowAtlasModalDialog(this.BtnReload, "cfd49834-05cc-4d45-9e80-a7bfc264ea6d", "质检单", "992", "504", null, null, true, false, false);
            this.QCList_Click_DefaultImpl(sender, e);
        }

        private void ShipList_Click_Extend(object sender, EventArgs e)
        {
            //弹出 出货单列表
            UIUtils.ShowListDialog(this, this.BtnReload, "1613e6c2-b79e-4225-a094-8c74f5709aa0", "出货单");
            //this.ShowAtlasModalDialog(this.BtnReload, "1613e6c2-b79e-4225-a094-8c74f5709aa0", "出货单", "992", "504", null, null, true, false, false);
            this.ShipList_Click_DefaultImpl(sender, e);
        }

        private void RcvList_Click_Extend(object sender, EventArgs e)
        {
            //弹出 收货单列表
            UIUtils.ShowListDialog(this, this.BtnReload, "a5a22611-d5db-4ffe-8d37-940905d94eb7", "收货单");
            //this.ShowAtlasModalDialog(this.BtnReload, "a5a22611-d5db-4ffe-8d37-940905d94eb7", "收货单", "992", "504", null, null, true, false, false);
            this.RcvList_Click_DefaultImpl(sender, e);
        }

        private void MOList_Click_Extend(object sender, EventArgs e)
        {
            //弹出生产订单列表
            UIUtils.ShowListDialog(this, this.BtnReload, "8f2521f2-91cb-45a5-80f9-0e63bd10bbfe", "生产订单");
            //this.ShowAtlasModalDialog(this.BtnReload, "8f2521f2-91cb-45a5-80f9-0e63bd10bbfe", "生产订单", "992", "504", null, null, true, false, false);
            this.MOList_Click_DefaultImpl(sender, e);
        }

        private void BtnUndoApprove_Click_Extend(object sender, EventArgs e)
        {
            this.BtnUndoApprove_Click_DefaultImpl(sender, e);
        }


        //BtnSave_Click...
        private void BtnSave_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			BtnSave_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnCancel_Click...
		private void BtnCancel_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			
		
			BtnCancel_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnAdd_Click...
		private void BtnAdd_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			//if (this.Model.IsDataChanged)
			//	throw new Exception("数据变动,请先保存");
		
			BtnAdd_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnDelete_Click...
		private void BtnDelete_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			
		
			BtnDelete_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnCopy_Click...
		private void BtnCopy_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			if (this.Model.AITBarCode.GetSelectedRecordIDs().Length == 0)
				throw new Exception("请选择记录");
			foreach (var record in this.Model.AITBarCode.GetSelectRecords())
			{
                AITBarCodeRecord rec=(AITBarCodeRecord)record;
                AITBarCodeRecord newrec = this.Model.AITBarCode.AddNewUIRecord();
				rec.CopyTo(newrec);
				newrec.BarCode = "";
				newrec.Printer = "";
				newrec.PrintNum = 0;
				newrec.PrintTime = null;
				newrec.DataRecordState = DataRowState.Added;
            }
		
			//BtnCopy_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnSubmit_Click...
		private void BtnSubmit_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			
		
			BtnSubmit_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnApprove_Click...
		private void BtnApprove_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			
		
			BtnApprove_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnFind_Click...
		private void BtnFind_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			
		
			BtnFind_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnList_Click...
		private void BtnList_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			
		
			BtnList_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnFirstPage_Click...
		private void BtnFirstPage_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			
		
			BtnFirstPage_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnPrevPage_Click...
		private void BtnPrevPage_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			
		
			BtnPrevPage_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnNextPage_Click...
		private void BtnNextPage_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			
		
			BtnNextPage_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnLastPage_Click...
		private void BtnLastPage_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			
		
			BtnLastPage_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnAttachment_Click...
		private void BtnAttachment_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			
		
			BtnAttachment_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnFlow_Click...
		private void BtnFlow_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			BtnFlow_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnOutput_Click...
		private void BtnOutput_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			BtnOutput_Click_DefaultImpl(sender,e);
		}	
		 
				//BtnPrint_Click...
		private void BtnPrint_Click_Extend(object sender, EventArgs  e)
		{
            //调用模版提供的默认实现.--默认实现可能会调用相应的Action.
            BtnPrint_Click_DefaultImpl(sender,e);
        }






		#region 自定义数据初始化加载和数据收集
		private void OnLoadData_Extend(object sender)
		{
			OnLoadData_DefaultImpl(sender);
		}
		private void OnDataCollect_Extend(object sender)
		{	
			OnDataCollect_DefaultImpl(sender);
		}
		#endregion  

        #region 自己扩展 Extended Event handler 
		public void AfterOnLoad()
		{
			
		}

        public void AfterCreateChildControls()
        {
            //启用个性化            
            UFIDA.U9.UI.PDHelper.PersonalizationHelper.SetPersonalizationEnable(this, true);

            //注册查找参照  可以写在BeforeUIModelBinding    
            //a001873c-ebb7-4e51-bcd4-7ce5698d1e2f是参照的FromID    
            UFIDA.U9.UI.PDHelper.PDFormMessage.ShowConfirmDialog(this.Page, "b51cfd86-db69-4510-8672-6b990e3d5812", "580", "408", Title, wpFindID.ClientID, this.BtnFind);

            //弹性域设置
            //实体扩展字段的启用：在单头上拖一个弹性域，单行容易忽略，是在单行上拖一个文本框，代码进行绑定。
            //单头弹性域设置
            //FlexFieldHelper.SetDescFlexField(new DescFlexFieldParameter[] { new DescFlexFieldParameter(this.FlexFieldPicker0, this.Model.DeliveryPlan) });
            //表体表格弹性域设置,DescFlexSegments是model中弹性域字段前缀
            FlexFieldHelper.SetDescFlexField(new DescFlexFieldParameter[] { new DescFlexFieldParameter(this.DataGrid1, this.DataGrid1.Columns.Count - 1, "DescFlexSegments") });
        }
        
        public void AfterEventBind()
        {
        }
        
		public void BeforeUIModelBinding()
		{
            if (this.CurrentSessionState["BarIDS"] != null)
            {
                var ids = (List<long>)this.CurrentSessionState["BarIDS"];
				UIUtils.LoadModelData(this, ids);
                this.CurrentSessionState["BarIDS"] = null;
            }
        }

		public void AfterUIModelBinding()
		{


		}


        #endregion
		
        #endregion
		
    }
}